package cn.edu.service.impl;
import cn.edu.entity.User;
import cn.edu.mapper.UserMapper;
import cn.edu.service.UserService;
import cn.edu.vo.LoginVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @author Mr.ma
 * @since 2022/11/17 14:43
 **/
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public Page<User> selectAll(Integer pageCount, Integer pageSize) {
        Page<User> page = new Page<>(pageCount,pageSize);
        Page<User> userPage = userMapper.selectPage(page, null);
        return userPage;
    }

    @Override
    public int insert(User user) {
        return userMapper.insert(user);
    }

    @Override
    public User selectById(int id) {
        return userMapper.selectById(id);
    }

    @Override
    public int updateById(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public int deleteById(int id) {
        return userMapper.deleteById(id);
    }

    @Override
    public User selectByNameAndPwd(LoginVO loginVO) {
        QueryWrapper<User> LoginWrapper=new QueryWrapper<>();
        LoginWrapper.eq("userName",loginVO.getUsername());
        LoginWrapper.eq("password",loginVO.getPassword());
        return userMapper.selectOne(LoginWrapper);
    }
}
